package com.dreamchaser.familydevice.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;

/***
 *
 *
 * @author: SJie
 * @Date: 2019/9/24 22:22
 * @description: 集合工具类
 *
 */
@Slf4j
public class CollectionUtils {

    /**
     * 集合对象映射
     * @param source
     * @param target
     * @param <T>   要转换成的目标对象类型
     * @return
     */
    public static  <T> List<T> copyProperties(List source, Class<T> target) {
        List<T> tList = new ArrayList<>();
        for (Object o : source) {
            T t = null;
            try {
                t = target.newInstance();
                BeanUtils.copyProperties(o, t);
                tList.add(t);
            } catch (InstantiationException e) {
                log.error("",e);
            } catch (IllegalAccessException e) {
                log.error("",e);
            }
        }
        return tList;

    }
}
